﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace UI
{
    public enum AutoChessTutorialEntries
    {
        gameInterface = 0, // 界面说明
        campsAndJobs = 1, // 阵营&果实能力
        heroChess = 2, // 英雄相关
        heroChessShop = 3 // 英雄商店
    }

    public class AutoChessTutorialSubPage : SubContentBase
    {
        public GameObject[] tutorialContent;
        public TextureKit[] textureKits;
        private GameObject curOpenContent;
        private string[] imageNames;

        // Use this for initialization
        private void Awake()
        {
            imageNames = Table.DataModel.TableConfig.autoChessExplainPageTutorialImages.Split(';');
        }

        public void OpenTab(int tabIdx)
        {
            if (tabIdx < 0 || tabIdx >= tutorialContent.Length)
            {
                ExLog.LogError("索引错误！");
                tabIdx = 0;
            }

            if (tabIdx > imageNames.Length)
            {
                ExLog.LogError("索引错误！超过了 Config 表中图片数量");
                tabIdx = 0;
            }

            if (curOpenContent != null)
            {
                curOpenContent.SetActive(false);
            }

            switch ((AutoChessTutorialEntries)tabIdx)
            {
                default:
                case AutoChessTutorialEntries.gameInterface:
                    curOpenContent = tutorialContent[tabIdx];
                    textureKits[tabIdx].TextureName = imageNames[tabIdx];
                    tutorialContent[tabIdx].SetActive(true);
                    break;
                case AutoChessTutorialEntries.campsAndJobs:
                    curOpenContent = tutorialContent[tabIdx];
                    textureKits[tabIdx].TextureName = imageNames[tabIdx];
                    tutorialContent[tabIdx].SetActive(true);
                    break;
                case AutoChessTutorialEntries.heroChess:
                    curOpenContent = tutorialContent[tabIdx];
                    textureKits[tabIdx].TextureName = imageNames[tabIdx];
                    tutorialContent[tabIdx].SetActive(true);
                    break;
                case AutoChessTutorialEntries.heroChessShop:
                    curOpenContent = tutorialContent[tabIdx];
                    textureKits[tabIdx].TextureName = imageNames[tabIdx];
                    tutorialContent[tabIdx].SetActive(true);
                    break;
            }
        }

        public override void OnShowTab()
        {
            base.OnShowTab();
            OpenTab(0);
        }

        public override void ReShowTab()
        {
            base.ReShowTab();
            this.gameObject.SetActive(true);
        }

        public override void CloseTab()
        {
            this.gameObject.SetActive(false);
            base.CloseTab();
        }
    }
}
